#include "service.h"

service::service(boost::asio::io_context& service, unsigned short port)
    : m_acceptor(service, tcp::endpoint(tcp::v4(), port))
    , m_socket(service)
    {

    }

    void service::do_accept()
    {
        m_acceptor.async_accept(
            m_socket, [this] (const boost::asio::error_code& error) {
                if (!error) {
                    // Creating a new session and start listing for
                    // client messages
                    make_shared_session(
                        std::move(m_socket),
                        m_emit
                    )->start();
                } else {
                    std::cerr << error.message() <<std::endl;
                }

                //listening to anohter client
                do_accept();
            }
        )
    }
